package henu.util;

import henu.DB.DB;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class Chat {
     private int chatID;
     private String chatName;
     private Date startTime;
     
     public Chat(int id){
         this.chatID =id ;
         if(!FromDb())
             this.chatID=-1;
     }
     private boolean FromDb() {
         int row = -1;
         String sql ="select * from chat where chat_id="+this.chatID;
         ResultSet rs = DB.RunSelect(sql);
         try{
             rs.last();
             row = rs.getRow();
             if(row == 1){
                 this.chatID = rs.getInt("CHAT_ID");
                 this.chatName = rs.getString("CHAT_NAME");
                 this.startTime = rs.getDate("START_TIME");
                 return true;
             }else
                 return false;
         }catch(SQLException e){
             e.printStackTrace();
             return false;
         }finally{
             DB.close();
         }
     }
     
     
	public int getChatID() {
		return chatID;
	}
	public void setChatID(int chatID) {
		this.chatID = chatID;
	}
	public String getChatName() {
		return chatName;
	}
	public void setChatName(String chatName) {
		this.chatName = chatName;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
}
